home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / dejagnu.lha / dejagnu-1.0.1 / tcl / tests / lindex.test < prev    next >
Text File  |  1992-11-06  |  2KB  |  63 lines

  1. # Commands covered:  lindex
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright 1991 Regents of the University of California
  8. # Permission to use, copy, modify, and distribute this
  9. # software and its documentation for any purpose and without
  10. # fee is hereby granted, provided that this copyright notice
  11. # appears in all copies.  The University of California makes no
  12. # representations about the suitability of this software for any
  13. # purpose.  It is provided "as is" without express or implied
  14. # warranty.
  15. #
  16. # $Header: /sprite/src/lib/tcl/tests/RCS/lindex.test,v 1.1 91/09/06 14:48:02 ouster Exp $ (Berkeley)
  17.  
  18. if {[string compare test [info procs test]] == 1} then {source defs}
  19.  
  20. test lindex-1.1 {basic tests} {
  21.     lindex {a b c} 0} a
  22. test lindex-1.2 {basic tests} {
  23.     lindex {a {b c d} x} 1} {b c d}
  24. test lindex-1.3 {basic tests} {
  25.     lindex {a b\ c\ d x} 1} {b c d}
  26. test lindex-1.4 {basic tests} {
  27.     lindex {a b c} 3} {}
  28. test lindex-1.5 {basic tests} {
  29.     list [catch {lindex {a b c} -1} msg] $msg
  30. } {0 {}}
  31.  
  32. test lindex-2.1 {error conditions} {
  33.     list [catch {lindex msg} msg] $msg
  34. } {1 {wrong # args: should be "lindex list index"}}
  35. test lindex-2.2 {error conditions} {
  36.     list [catch {lindex 1 2 3 4} msg] $msg
  37. } {1 {wrong # args: should be "lindex list index"}}
  38. test lindex-2.3 {error conditions} {
  39.     list [catch {lindex 1 2a2} msg] $msg
  40. } {1 {expected integer but got "2a2"}}
  41. test lindex-2.4 {error conditions} {
  42.     list [catch {lindex "a \{" 2} msg] $msg
  43. } {1 {unmatched open brace in list}}
  44. test lindex-2.5 {error conditions} {
  45.     list [catch {lindex {a {b c}d e} 2} msg] $msg
  46. } {1 {list element in braces followed by "d" instead of space}}
  47. test lindex-2.6 {error conditions} {
  48.     list [catch {lindex {a "b c"def ghi} 2} msg] $msg
  49. } {1 {list element in quotes followed by "def" instead of space}}
  50.  
  51. test lindex-3.1 {quoted elements} {
  52.     lindex {a "b c" d} 1
  53. } {b c}
  54. test lindex-3.2 {quoted elements} {
  55.     lindex {"{}" b c} 0
  56. } {{}}
  57. test lindex-3.3 {quoted elements} {
  58.     lindex {ab "c d \" x" y} 1
  59. } {c d " x}
  60. test lindex-3.4 {quoted elements} {
  61.     lindex {a b {c d "e} {f g"}} 2
  62. } {c d "e}
  63.